package com.bestcem.xm.ticket.job;

import com.bestcem.xm.componet.xxljob.annotation.XxlRegister;
import com.bestcem.xm.ticket.task.NotificationTask;
import com.bestcem.xm.ticket.task.RspdTimerTask;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class TicketJobService {

    private static final Logger logger = LoggerFactory.getLogger(TicketJobService.class);

    @Resource
    RspdTimerTask rspdTimerTask;

    @Resource
    private NotificationTask notificationTask;

    @XxlJob(value = "ticket-condition-job")
    //@XxlRegister(cron = "0 */1 * * * ?", triggerStatus = 1, jobDesc = "预警规则答卷状态条件检查定时任务")
    @XxlRegister(cron = "${app.ticket.task.condition-cron:0 * * * * ?}", triggerStatus = 1, jobDesc = "预警规则答卷状态条件检查定时任务")
    public void rspdStatusJob() {
        logger.info("[ticket] 预警规则答卷状态条件检查任务开始");
        rspdTimerTask.rspdStatusTimer();
        logger.info("[ticket] 预警规则答卷状态条件检查任务结束");
    }

    @XxlJob(value = "ticket-notify-job")
    //@XxlRegister(cron = "0 0 0 */1 * ?", triggerStatus = 1, jobDesc = "通知提醒定时任务")
    @XxlRegister(cron = "${app.ticket.task.notify-cron:0 0 0 /1 * ? }", triggerStatus = 1, jobDesc = "通知提醒定时任务")
    public void notificationJob() {
        logger.info("[ticket] 通知提醒任务开始");
        notificationTask.calPeriodNotification();
        logger.info("[ticket] 通知提醒任务结束");
    }
}
